import 'package:flutter_baselib/flutter_baselib.dart';
import 'package:logger/logger.dart';

///@date:  2023-10-24 11:00:37
///@author:  MuFeng
///@description: 基础库
class BaseLibPlugin {
  BaseLibPlugin._();

  ///是否是debug模式
  static bool _isDebug = true;

  ///全局资源配置类
  static late IResConfig _resConfig;

  static bool get isDebug => _isDebug;

  static IResConfig get resConfig => _resConfig;

  ///初始化基础库,应用启动时调用
  ///[isDebug] 是否是debug模式
  ///[httpConfig] http相关配置信息
  ///[resConfig] 全局通用资源配置
  ///[toastImpl] Toast相关配置，为null使用默认Toast样式
  static Future<void> init({
    required bool isDebug,
    required IHttpConfig httpConfig,
    required IResConfig resConfig,
    IToast? toastImpl,
  }) async {
    _isDebug = isDebug;
    _resConfig = resConfig;

    Constants.initPageIndex = _resConfig.configInitPageIndex();
    Constants.pageSize = _resConfig.configPageSize();

    ///初始化日志库
    LogUtils.init(Logger(
        printer: PrettyPrinter(
            // Number of method calls to be displayed
            methodCount: 2,
            // Number of method calls if stacktrace is provided
            errorMethodCount: 8,
            // Width of the output
            lineLength: 120,
            // Colorful log messages
            colors: true,
            // Print an emoji for each log message
            printEmojis: true,
            // Should each log print contain a timestamp
            printTime: false)));

    ///初始化Toast
    ToastUtils.init(toastImpl);

    ///初始化http组件
    XApi.init(httpConfig);
  }

  ///应用关闭时调用该方法
  static Future<void> dispose() async {

  }
}
